package com.qzd.singleton.lazy;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 使用一个map，创建对象存入map中
 */
public class ContainerSingleton {
    private ContainerSingleton() {
    }

    private static Map<String, Object> ioc = new ConcurrentHashMap<String, Object>();

    public static Object getInstance(String classname) {
        Object o = null;
        if (!ioc.containsKey(classname)) {
            try {
                o = Class.forName(classname).newInstance();
                ioc.put(classname, o);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return o;
        } else {
            return ioc.get(classname);
        }
    }

}
